<script type="text/javascript">
var errors=false;
function check(input)
{
		var div='#'+input+'Info';
		var ele = $('#'+input);
		if (ele.val().length<2)
		{
			if ($(div).length<=0)  //questo metodo controlla l'esistenza del div
			{
				$('#ricerca').append('<div id="'+input+'Info" class="info"></div>');
				var typeInfo = $('#'+input+'Info');
				var pos = ele.offset();
				typeInfo.css({
					top: pos.top-3,
				left: pos.left+ele.width()+15
				});
				typeInfo.removeClass('correct').addClass('error').html('&larr; Inserire almeno 2 caratteri').fadeIn();
				ele.removeClass('normal').addClass('wrong');				
			}
			
		}
		else
		{		
		  var typeInfo = $('#'+input+'Info');
			var pos = ele.offset();
			typeInfo.css({
			top: pos.top-3,
			left: pos.left+ele.width()+15
			});
		if( ele.val().length<3) {
			  typeInfo.removeClass('correct').addClass('error').html('&larr; Inserire almeno 2 caratteri').show();
				ele.removeClass('normal').addClass('wrong');	
		} else{
				typeInfo.removeClass('error').addClass('correct').html('&radic;').show();
				ele.removeClass('wrong').addClass('normal');
				errors=true;
		} 
		}
}	
	
function sostituisciSpazio(stringa)
{
	var parts = stringa.split(' '),
            len = parts.length,i;
			var ind='';
        	for(i = 0; i < len-1; i += 1) {
            	ind += parts[i]+'%20';
        	} 
		    ind+=parts[len-1];
			return ind;
}


$('#button').click(function (){
	var obj = $('#ricerca');
	obj.animate({ scrollTop: $('#nuovocliente').offset().top }, 750, function (){
		errors=false;
		check('cognome');
		check('nome');
		check('indirizzo');
		if(errors) {
			var jrole = "ricezione/salvacliente.php";
			var data="cognome='"+sostituisciSpazio($('#cognome').val())+"'&nome='"+sostituisciSpazio($('#nome').val());
			data=data+"'&ind='"+sostituisciSpazio($('#indirizzo').val());
			data=data+"'&city='"+sostituisciSpazio($('#citta').val())+"'&provincia='"+$('#prov').val()+"'&telcasa='"+$('#telcasa').val();
			data=data+"'&telcellu='"+$('#telcellu').val()+"'&mail='"+$('#mail').val()+"'";
			jrole=jrole+"?"+data;
			$('#salvacliente').slideUp(1000,function(){$('#salvacliente').load(jrole,'',$('#salvacliente').slideDown(1000))});
			
			return false;
		}
	});
	return false;
});


// ======================================================  //
</script>
<form name="nuovocliente" id="nuovocliente" action="#" method="get">
<table align="center">
    <tr valign="baseline">
      <td nowrap="nowrap" align="right">Cognome*:</td>
      <td><input type="text" name="Cognome" size="32" id="cognome" onkeyup="check(this.id);"/></td>
    </tr>
    <tr valign="baseline">
      <td nowrap="nowrap" align="right">Nome*:</td>
      <td><input type="text" name="Nome" value="" size="32" id="nome" onkeyup="check(this.id);"/></td>
    </tr>
    <tr valign="baseline">
      <td nowrap="nowrap" align="right">Indirizzo*:</td>
      <td><input type="text" name="Indirizzo" value="" size="32" id="indirizzo" onkeyup="check(this.id);"/></td>
    </tr>
    <tr valign="baseline">
      <td nowrap="nowrap" align="right">Citt&agrave;:</td>
      <td><input type="text" name="City" value="" size="32" id="citta" /></td>
    </tr>
    <tr valign="baseline">
      <td nowrap="nowrap" align="right">Provincia:</td>
      <td><input type="text" name="provincia" value="" size="32" id="prov"/></td>
    </tr>
    <tr valign="baseline">
      <td nowrap="nowrap" align="right">Telefono di casa:</td>
      <td><input type="text" name="Telcasa" value="" size="32" id="telcasa"/></td>
    </tr>
    <tr valign="baseline">
      <td nowrap="nowrap" align="right">Cellulare:</td>
      <td><input type="text" name="TelCellu" value="" size="32" id="telcellu"/></td>
    </tr>
    <tr valign="baseline">
      <td nowrap="nowrap" align="right">Mail:</td>
      <td><input type="text" name="Mail" value="" size="32" id="mail"/></td>
    </tr>
    <tr valign="baseline">
      <td colspan="2" align="center" nowrap="nowrap"><button type="submit" id="button">Inserisci</button></td>
    </tr>
  </table>
</form>
<div id="salvacliente">&nbsp;</div>